<template>
	<view class="uni_box home">
		<navbar title='我的券包'>
		</navbar>
		<u-sticky offset-top="0">
			<view class="sctab">
				<u-tabs :list="tablist" bg-color="#fff" :is-scroll="false" :current="current" @change="change" active-color="rgba(255, 77, 67, 1)" inactive-color="#666"></u-tabs>
			</view>
		</u-sticky>
		
		<view class="content">
			<view class="quanitem" v-for="(item,index) in list" :key="index">
				<image class="bg" v-if="item.status == 0" src="@/pages_client/static/img/quanbg.png" mode="" />
				<image class="bg" v-else src="@/pages_client/static/img/bg_youhuiquan_n.png" mode="" />
				<view class="quans">
					<view class="quanleft">
						<text class="qname">{{item.name}}</text>
						<text class="qtime">{{item.starttime+'-'+item.endtime}}</text>
					</view>
					<view class="qright">
						<text class="jia">¥<text class="jianum">{{item.money}}</text></text>
						<text class="man">满￥{{item.need}}使用</text>
						<view class="shiyong" v-if="item.status == 0">立即使用</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="status" @loadmore="loadmore" v-if="list !=''" /> 
			<u-empty text="暂无数据" mode="list" v-if="list ==''"></u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tablist: [{
					name: '待使用'
				}, {
					name: '已使用'
				}, {
					name: '已过期'
				}],
				current: 0,
				list: [],
				page: 1,
				limit: 10,
				last_page: 1,
				status: "loadmore",

			}
		},
		onLoad() {
			this.getList()
		},
		onShow() {
		},
		onReachBottom: function () {
			this.loadmore();
		},
		methods: {
			async getList(){
				let res = await this.$u.api.getCounponList({
					status:this.current,
					limit:this.limit,
					page:this.page,
				});
					console.log(res.length)
					// this.last_page = res.lastpage;
					let list = res.list;
					this.list = this.page == 1 ? list : [...this.list, ...list];	
					if(res.list==''||Number(list.length)<Number(this.limit)){
						this.status = 'nomore';
					}
			},
			loadmore() {
				let page = this.page;
				// let last_page = this.last_page;
				if (this.status == 'loadmore') {
					this.page++;
					this.getList();
				}
			},
			change(e){
				this.current = e
				this.getClear()
			},
			getClear(){
				this.list = []
				this.page = 1,
				this.status= "loadmore"
				this.getList()
			}
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #f5f5f5;
	}
	.content{
		background-color: #f5f5f5;
		padding: 30rpx 25rpx;
		.quanitem{
			position: relative;
			height: 220rpx;
			margin-bottom: 20rpx;
			.quans{
				position: relative;
				display: flex;
				width: 100%;
				height: 100%;
				flex-direction: row;
				.quanleft{
					height: 100%;
					width: 50%;
					display: flex;
					flex-direction: column;
					justify-content: center;
					padding-left: 45rpx;
					.qname{
						font-weight: bold;
						font-size: 36rpx;
						color: #222222;
					}
					.qtime{
						font-weight: 500;
						font-size: 22rpx;
						color: #222222;
						display: block;
						margin-top: 8rpx;
					}
				}
				.qright{
					height: 100%;
					margin-left: auto;
					width: 30%;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					.jia{
						font-weight: bold;
						font-size: 40rpx;
						color: #FFFFFF;
						.jianum{
							font-size: 60rpx;
							display: inline-block;
							position: relative;
							margin-left: 3rpx;
						}
					}
					.man{
						font-weight: bold;
						font-size: 22rpx;
						color: #FFFFFF;
					}
					.shiyong{
						width: 128rpx;
						height: 42rpx;
						background: #FFFFFF;
						border-radius: 21rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						font-weight: 500;
						font-size: 20rpx;
						color: #EA5918;
						margin-top: 10rpx;
					}
				}
			}
		}
	}
</style>
